package com.ruoyi.electricity.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.electricity.domain.vo.*;
import com.ruoyi.electricity.service.ElectricityStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/electricity/statistics")
public class ElectricityStatisticsController  extends BaseController {
    @Autowired
    private ElectricityStatisticsService electricityStatisticsService;
    /**
     * 统计近七天“总用电一回”和“总用电二回”每天消耗的电能之和
     */
    @GetMapping("countTotalElectricityConsumptionInSevenDays")
    private AjaxResult countTotalElectricityConsumptionInSevenDays(@RequestParam Integer days) {
        List<PAEnergyForEveryDay> res = electricityStatisticsService.countTotalElectricityConsumptionInSevenDays(days);
        return AjaxResult.success(res);
    }
    /**
     * 统计用电设备中：开、停、离 三种状态的个数
     */
    @GetMapping("countOpenStopOffline")
    public  AjaxResult countOpenStopOffline() {
        List<OpenStopOfflineCount> res = electricityStatisticsService.countOpenStopOffline();
        return AjaxResult.success(res);
    }
    /**
     * a. 统计一段时间内，某设备每天的：电能
     */
    @GetMapping("countPAEnergyForEveryDay")
    public AjaxResult countPAEnergyForEveryDay(@RequestParam Date startTime,@RequestParam Date endTime, String equipCode) {
        List<PAEnergyForEveryDay> res = electricityStatisticsService.countPAEnergyForEveryDay(startTime, endTime, equipCode);
        return AjaxResult.success(res);
    }
    /**
     * b.统计一段时间内，每天的：报警总数、未处理的报警数、已处理的报警数
     */
    @GetMapping("countAlarmsForEveryDay")
    public AjaxResult countAlarmsForEveryDay(@RequestParam Date startTime,@RequestParam Date endTime) {
        List<AlarmsCountForEveryDay> res = electricityStatisticsService.countAlarmsForEveryDay(startTime, endTime);
        return AjaxResult.success(res);
    }
    /**
     * c.统计一段时间内，各设备的：报警次数（排行榜）
     */
    @GetMapping("countALarmForEachEquip")
    public AjaxResult countALarmForEachEquip(@RequestParam Date startTime, @RequestParam Date endTime) {
        List<ALarmCountForEachEquip> res = electricityStatisticsService.countALarmForEachEquip(startTime, endTime);
        return AjaxResult.success(res);
    }
    /**
     * d.统计一段时间内，一、二、三、四级报警的总数
     */
    @GetMapping("countTotalAlarmForEachLevel")
    public AjaxResult countAlarmForEachLevel(Date startTime, Date endTime) {
        List<AlarmCountForEachLevel> res  = electricityStatisticsService.countAlarmForEachLevel(startTime, endTime);
        return AjaxResult.success(res);
    }

    /**
     * 统计各设备当天的电能（此刻的总电能 - 当天0点时的总电能）
     */
    @GetMapping("countPAEnergyForTheDay")
    public AjaxResult countPAEnergyOfEachEquipForTheDay() {
        List<PAEnergyCountForTheDay> res = electricityStatisticsService.countPAEnergyForTheDay();
        return AjaxResult.success(res);
    }

    /**
     * 统计当天一、二、三、四级报警总数、未处理的报警数、已处理的报警数
     */
    @GetMapping("countEveryAlarmLevelForTheDay")
    public AjaxResult countEveryAlarmLevelForTheDay() {
        List<AlarmsHandleCountForTheDay> res = electricityStatisticsService.countEveryAlarmLevelForTheDay();
        return AjaxResult.success(res);
    }

    /**
     * 统计此时各设备中正常的有多少个，预警（存在风险）的有多少个，报警（不安全）的有多少个
     *
     */
    @GetMapping("countEquipSecurityStatus")
    public AjaxResult countEquipSecurityStatus() {
        List<EquipSecurityStatusCount> res = electricityStatisticsService.countEquipSecurityStatus();
        return AjaxResult.success(res);
    }
    /**
     * 查询当天最近12小时的报警总数、未处理的报警数、已处理的报警数
     */
    @GetMapping("countAlarmsForEachHourOfTheDay")
    public AjaxResult countAlarmsForEachHourOfTheDay() {
        List<AlarmsHandleCountForEachHourOfTheDay> res = electricityStatisticsService.countAlarmsForEachHourOfTheDay();
        return AjaxResult.success(res);
    }


    /**
     * 查询某设备当天各时分的用电信息
     */

    @GetMapping("selectElectricityDataEveryMinuteOfTheDay")
    public AjaxResult selectElectricityDataEveryMinuteOfTheDay(String equipCode, Date date) {
        List<ElectricityDataVo> res = electricityStatisticsService.selectElectricityDataEveryMinuteOfTheDay(equipCode, date);
        return AjaxResult.success(res);
    }

    /**
     * 查询某用电设备的平均用电和最大用电
     */
    @GetMapping("selectMaxAndAvgElectricityOfTheDay")
    public AjaxResult selectMaxAndAvgElectricityOfTheDay(String equipCode) {
        List<MaxAndAvgElectricityVo> res = electricityStatisticsService.selectMaxAndAvgElectricityOfTheDay(equipCode);
        return AjaxResult.success(res);
    }

    /**
     * 1.不同区域的用电量排行榜 （区域的用电量是该区域中所有设备的日用点之和）
     *  t_electricity_data
     *
     */
    @GetMapping("selectRegionalElectricityConsumptionRanking")
    public AjaxResult selectRegionalElectricityConsumptionRanking() {
        List<RegionalElectricityConsumptionRanking> res = electricityStatisticsService.selectRegionalElectricityConsumptionRanking();
        return AjaxResult.success(res);
    }
    /**
     * 2.全部设备的的当月用电量和产出的变化趋势(时间变化柱状图)
     *  t_electricity_data
     *
     */
    @GetMapping("selectDailyElectricityConsumptionAndOutputForCurrentMonth")
    public AjaxResult selectDailyElectricityConsumptionAndOutputForCurrentMonth() {
        List<ElectricityConsumptionAndOutputInTimeDimension> res = electricityStatisticsService.selectDailyElectricityConsumptionAndOutputForCurrentMonth();
        return AjaxResult.success(res);
    }
    /**
     * 3. 统计各electricType的用电量(饼图)
     *  t_electricity_data
     *
     */
    @GetMapping("selectPowerConsumptionOfEachElectricityType")
    public AjaxResult selectPowerConsumptionOfEachElectricityType() {
        List<ElectricityTypePowerConsumption> res = electricityStatisticsService.selectPowerConsumptionOfEachElectricityType();
        return AjaxResult.success(res);
    }


    /**
     * 4. 统计当月每天的报警次数
     *  t_risk_warnings
     */
    @GetMapping("selectDailyElectricityAlarmForCurrentMonth")
    public AjaxResult selectDailyElectricityAlarmForCurrentMonth() {
        List<ElectricityAlarmCountInTimeDimension> res = electricityStatisticsService.selectDailyElectricityAlarmForCurrentMonth();
        return AjaxResult.success(res);
    }


    /**
     * 5. 统计当月各报警级别的报警个数
     *  t_risk_warnings
     */
    @GetMapping("selectNumberOfEachElectricityAlarmLevelForCurrentMonth")
    public AjaxResult selectNumberOfEachElectricityAlarmLevelForCurrentMonth() {
        List<ElectricityAlarmLevelCount> res = electricityStatisticsService.selectNumberOfEachElectricityAlarmLevelForCurrentMonth();
        return AjaxResult.success(res);
    }

    /**
     * 6.统计当天各在线状态的个数
     * t_data_gateway_system
     */
    @GetMapping("selectNumberOfEachOnlineStatusForCurrentDay")
    public AjaxResult selectNumberOfEachOnlineStatusForCurrentDay() {
        List<OnlineStatusCount> res = electricityStatisticsService.selectNumberOfEachOnlineStatusForCurrentDay();
        return AjaxResult.success(res);
    }

    /**
     *
     * 7.统计当月每天，各隐患状态的个数
     * t_data_gateway_system
     *
     */
    @GetMapping("selectNumberOfEachHiddenSateForCurrentMonth")
    public AjaxResult selectNumberOfEachHiddenSateForCurrentMonth() {
        List<HiddenSateCountInTimeDimension> res = electricityStatisticsService.selectNumberOfEachHiddenSateForCurrentMonth();
        return AjaxResult.success(res);
    }

}
